package com.shenmazong.servereduuser.controller;


import com.shenmazong.servereduuser.entity.TbUser;
import com.shenmazong.servereduuser.service.ITbUserService;
import com.shenmazong.servereduuser.vo.UserVo;
import com.shenmazong.utils.ResultResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 关好帅
 * @since 2021-09-14
 */
@RestController
@Slf4j
public class TbUserController {
    @Autowired
    private ITbUserService userService;
    @PostMapping(value = "/publicKey")
    public ResultResponse publicKey() {
        HashMap<String, Object> dataMap = new HashMap<>();
        dataMap.put("mockServer", "true");
        dataMap.put("publicKey", "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBT2vr+dhZElF73FJ6xiP181txKWUSNLPQQlid6DUJhGAOZblluafIdLmnUyKE8mMHhT3R+Ib3ssZcJku6Hn72yHYj/qPkCGFv0eFo7G+GJfDIUeDyalBN0QsuiE/XzPHJBuJDfRArOiWvH0BXOv5kpeXSXM8yTt5Na1jAYSiQ/wIDAQAB");
        return ResultResponse.SUCCESS(dataMap);
    }

    @PostMapping(value = "/login")
    public ResultResponse login(@RequestBody TbUser user) {
        return userService.login(user);
    }

    @PostMapping(value = "/register")
    public ResultResponse register(@RequestBody UserVo user){
        return userService.register(user);
    }

    @PostMapping(value = "/userInfo")
    public ResultResponse userInfo(@RequestBody Object baseVo) {
        log.info(baseVo.toString());
        ArrayList<String> permissons = new ArrayList<>();
        permissons.add("admin");

        HashMap<String, Object> dataMap = new HashMap<>();
        dataMap.put("permissions", permissons);
        dataMap.put("username", "admin");
        dataMap.put("avatar", "https://i.gtimg.cn/club/item/face/img/2/15922_100.gif");
        return ResultResponse.SUCCESS(dataMap);
    }

    @PostMapping("sendCode/{phone}")
    public ResultResponse sendCode(@PathVariable("phone") String phone){
        return userService.sendCode(phone);
    }


}
